import 'package:flutter/material.dart';
import './index_navigator_item.dart';
import '../../../router/routes.dart';

class IndexNavigator extends StatefulWidget {
  const IndexNavigator({super.key});

  @override
  State<IndexNavigator> createState() => _IndexNavigatorState();
}

class _IndexNavigatorState extends State<IndexNavigator> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(top: 6, bottom: 15),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: navigatorItemList.map((item) {
          return _buildNavItem(context, item);
        }).toList(),
      ),
    );
  }
}

// 单独构建导航项组件
Widget _buildNavItem(BuildContext context,IndexNavigatorItem item) {
  return InkWell(
    onTap: () {
      // 简化路由导航逻辑
      Navigator.pushNamed(context, Routes.login);
    },
    child: Column(
      mainAxisSize: MainAxisSize.min, // 添加此属性优化布局
      children: [
        SizedBox(
          // 替换 Expanded 为 SizedBox
          height: 34.5,
          child: Image.asset(
            item.imageUri,
            fit: BoxFit.contain,
            errorBuilder: (context, error, stackTrace) {
              return Icon(Icons.image, size: 24);
            },
          ),
        ),
        //SizedBox(height: 7),
        Text(
          item.title,
          style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
          overflow: TextOverflow.ellipsis,
        ),
      ],
    ),
  );
}
